{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from os.path import exists\n",
    "def find_riverobs_test_data_dir():\n",
    "    \"\"\"Fin the location of the test data root directory\"\"\"\n",
    "    \n",
    "    if 'RIVEROBS_TESTDATA_DIR' in os.environ:\n",
    "        test_data_dir = os.environ('RIVEROBS_TESTDATA_DIR')\n",
    "    else: # try the default location\n",
    "        test_data_dir = '../../../RiverObsTestData'\n",
    "        \n",
    "    if not exists(test_data_dir):\n",
    "        print('You must either set the environment variable RIVEROBS_TESTDATA_DIR')\n",
    "        print('or locate the test data directory at ../../../RiverObsTestData')\n",
    "        raise Exception('Test data directory not found.')\n",
    "        \n",
    "    return test_data_dir\n",
    "\n",
    "data_dir = find_riverobs_test_data_dir()\n",
    "data_dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from glob import glob\n",
    "from os.path import join, splitext, split\n",
    "from GWDLR import GWDLR2shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gwdlr_data_dir = join(data_dir,'GWDLR')\n",
    "output_dir = join(gwdlr_data_dir,'GWD-LRVectors','na1')\n",
    "min_width = 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bin_file = glob(join(gwdlr_data_dir,'*.bin'))\n",
    "bin_file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g2s = GWDLR2shape(gwdlr_data_dir,output_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for tile in bin_file:\n",
    "    rootname = splitext(split(tile)[1])[0]\n",
    "    print 'Processing: ',tile\n",
    "    g2s.process_tile(rootname,min_width)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
